#include "ge_internal.h"

GE_PSP_INFO("LibGE Test", 1, 0, 256);

int main(int argc, char** argv){
	geDebugMode(GE_DEBUG_ALL);
	geInit();
	geCreateMainWindow("", -1, -1, GE_WINDOW_FULLSCREEN);
	geClearColor(RGBA(64, 64, 128, 255));
	geCursorRoundMode(true);
	geWaitVsync(true);

	ge_Keys* keys = geCreateKeys();
	ge_Font* font = geLoadFont("");
	
	ge_GuiWindow* win = geGuiCreateWindow("", 480, 272, GE_WINDOW_FULLSCREEN | GE_WINDOW_FULLWINDOW | GE_WINDOW_TRANSPARENT);
	geGuiStyleFont(win->style, font, 8);

	ge_Image* test = geLoadImage("data/image.png");
	while(1){
		geClearScreen();
		geBlitImageStretched(0, 0, test, 0, 0, test->width, test->height, test->width/2, test->height/2, GE_BLIT_NOALPHA);
		geSwapBuffers();
	}

	ge_Camera* cam = geCreateCamera();
	geCameraSetMaximumAngles(cam, -89.0, 89.0, GE_CAMERA_VERTICAL);
	cam->x = 0.0;
	cam->y = 0.0;
	cam->z = 1.8;
	
//	ge_Scene* scene = geLoadScene("ms0:/PSP/GAME/LibGE/data/scene.ge3d");
	ge_Scene* scene = geLoadScene("data/scene.ge3d");
	ge_Light* light = scene->renderers[0].lights[0];

	float ca = 0.0;
	float la = 0.0;

	bool AA = true;
	int shake = 0;
	
	while(1){
		geReadKeys(keys);
		if(keys->pressed[GEK_TRIANGLE]){
			geCameraMoveForward(cam, 5.0);
		}
		if(keys->pressed[GEK_CROSS]){
			geCameraMoveBack(cam, 5.0);
		}
		if(keys->pressed[GEK_SQUARE]){
			geCameraMoveLeft(cam, 5.0);
		}
		if(keys->pressed[GEK_CIRCLE]){
			geCameraMoveRight(cam, 5.0);
		}
		if(keys->pressed[GEK_RTRIGGER]){
			cam->z += 0.4;
		}
		if(keys->pressed[GEK_LTRIGGER]){
			cam->z -= 0.4;
		}
		if(geKeysToggled(keys, GEK_SELECT)){
			AA = !AA;
		}
	
		light->position.x = 1000.0 * geCos(la);
		light->position.y = 1000.0 * geSin(la);
		la += 0.1;

		geDrawingMode(GE_DRAWING_MODE_3D);
		geClearScreen();

		geCameraRotateWithMouse(cam, 0.4);
		if(AA){
			if(shake){
				cam->RotH_rad += 0.001;
				cam->RotV_rad += 0.001;
			}else{
				cam->RotH_rad -= 0.001;
				cam->RotV_rad -= 0.001;
			}
			shake = !shake;
			geCameraFromAngles(cam, cam->RotH_rad, cam->RotV_rad);
		}
		geCameraLook(cam);
		geSceneDraw(scene);
		
		geDrawingMode(GE_DRAWING_MODE_2D);
		geFontPrintfScreen(0, font->size * 0, font, 0xFFFFFFFF, "FPS : %d", geFps());
		geFontPrintfScreen(0, font->size * 1, font, 0xFFFFFFFF, "RAM : %d KB", geGetContext()->mem / 1024);
		geFontPrintfScreen(0, font->size * 2, font, 0xFFFFFFFF, "VRAM : %d KB", geGetContext()->gpumem / 1024);
		geSwapBuffers();
	}

	geQuit();
	return 0;
}
